﻿using System;
using System.Collections.Generic;
using System.Web.Configuration;
using System.Linq;
using System.Text;
using Think.Lenovo.Com.DataAccess;
using Think.Lenovo.Com.Models;
using Think.Lenovo.Com.Common;
using System.Web.Mvc;
using System.Data;
namespace Think.Lenovo.Com.Controllers
{
    public class ChinaRegionController : Controller
    {
        /// <summary>
        /// 返回json格式数据,数据是国内所有省的信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ActionResult GetAllProvince() 
        {
            JsonResult jr = new JsonResult();
            jr.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
            try
            {
                RegionInfo ri = new RegionInfo();
                LinkedList<RegionModel> list = ri.GetAllProvince();
                jr.ContentEncoding = System.Text.Encoding.UTF8;
                jr.Data = list;
            }
            catch (Exception e)
            {
                String logFolder = WebConfigurationManager.AppSettings["LogRoot"];
                Log.RecordLog(logFolder, e);
            }
            return jr;
        }

        /// <summary>
        /// 返回json格式数据,数据是国内某省的城市信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ActionResult GetCitiesByProvince(int id)
        {
            JsonResult jr = new JsonResult();
            jr.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
            try
            {
                RegionInfo ri = new RegionInfo();
                LinkedList<RegionModel> list = ri.GetCitiesByProvince(id);
                jr.ContentEncoding = System.Text.Encoding.UTF8;
                jr.Data = list;
            }
            catch (Exception e)
            {
                String logFolder = WebConfigurationManager.AppSettings["LogRoot"];
                Log.RecordLog(logFolder, e);
            }
            return jr;
        }
    }
}
